package com.example.palette.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;


import com.example.palette.R;
import com.example.palette.bean.FileDetected;

import java.util.List;

public class DirAdapter extends BaseAdapter<FileDetected> {

    public DirAdapter(int layoutId, List<FileDetected> datas) {
        super(layoutId, datas);
    }

    @Override
    public void bindViews(BaseHolder holder, FileDetected fileDetected, int position) {
        TextView name = holder.getView(R.id.tv_rv_dir_item_name);
        ImageView next = holder.getView(R.id.tv_rv_dir_item_next);
        name.setVisibility(View.VISIBLE);
        name.setText(fileDetected.getName());
        name.setTag(R.id.dir_name_id,fileDetected);
        name.setTag(R.id.dir_name_position,position);
        if(position == datas.size() - 1){
            next.setVisibility(View.GONE);
        }else {
            next.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void bindListener(BaseHolder holder) {
        TextView name = holder.getView(R.id.tv_rv_dir_item_name);
        name.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(onItemClickListen != null){
                    onItemClickListen.onItemClick((FileDetected) name.getTag(R.id.dir_name_id), (Integer) name.getTag(R.id.dir_name_position),R.id.tv_rv_dir_item_name);
                }
            }
        });
    }
}
